/*
 * @Author: 刘岩 15136056318@163.com
 * @Date: 2023-02-17 21:48:26
 * @LastEditors: 刘岩 
 * @LastEditTime: 2023-03-15 14:30:12
 * @FilePath: \template3-h5\src\store\index.js
 * @Description:
 *
 */
import { createPinia } from 'pinia'
const pinia = createPinia()
// 数据持久化插件
pinia.use(({ store }) => {
  if (localStorage.getItem(store.$id)) {
    const pinia = JSON.parse(localStorage.getItem(store.$id))
    store.$state = pinia
  }
  store.$subscribe(() => {
    // 响应 store 变化
    localStorage.setItem(store.$id, JSON.stringify(store.$state))
  })
})
export default pinia
